#include "my_time.h"
#include <omp.h>

int main() {
  MyTimeI;
  MyTimeA;

  int sum = 0;
  int i;
  int myid;
  constexpr int n = 10;
  int a[n][n]{1, 5, 8,  3,  3,  6, 8,  4, 1,  2,  6,  9,  2,  8,  9, 9, 5,
              4, 6, 2,  4,  5,  9, 2,  4, 88, 78, 9,  6,  52, 54, 8, 9, 6,
              5, 3, 6,  7,  4,  1, 2,  5, 9,  78, 7,  4,  5,  56, 5, 4, 52,
              6, 8, 7,  8,  8,  7, 9,  4, 5,  1,  32, 85, 7,  9,  5, 4, 1,
              3, 5, 7,  4,  59, 8, 4,  1, 5,  7,  7,  54, 5,  5,  5, 8, 58,
              4, 5, 41, 85, 21, 5, 58, 7, 65, 6,  9,  8,  74, 7,  85};
#pragma omp parallel reduction(+ : sum) private(i, myid) num_threads(8)
  {
    myid = omp_get_thread_num(); // 获取线程号
    for (i = 0; i < n; i++)
      sum += a[myid][i];
    printf("thread %d, sum %d \n", myid, sum);
  }

  printf("total sum: %d\n ", sum);

  MyTimeB;
  return 0;
}